package com.jzo2o.customer.controller.agency;


import com.jzo2o.api.publics.SmsCodeApi;
import com.jzo2o.api.publics.dto.response.BooleanResDTO;
import com.jzo2o.common.enums.SmsBussinessTypeEnum;
import com.jzo2o.customer.model.dto.request.InstitutionRegisterReqDTO;
import com.jzo2o.customer.model.dto.request.InstitutionResetPasswordReqDTO;
import com.jzo2o.customer.model.dto.response.ServeProviderInfoResDTO;
import com.jzo2o.customer.service.IServeProviderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 服务人员/机构表 前端控制器
 * </p>
 *
 * @author itcast
 * @since 2023-07-17
 */
@RestController("agencyServeProviderController")
@RequestMapping("/agency/serve-provider")
@Api(tags = "机构端 - 服务人员或机构相关接口")
@Slf4j
public class ServeProviderController {
    @Resource
    private IServeProviderService serveProviderService;
    @Resource
    private SmsCodeApi smsCodeApi;

    @PostMapping("/institution/resetPassword")
    public void resetPassword(@RequestBody InstitutionRegisterReqDTO registerReqDTO) {
        log.info("机构重置密码：{}", registerReqDTO);
        BooleanResDTO verify = smsCodeApi.verify(registerReqDTO.getPhone(), SmsBussinessTypeEnum.INSTITUTION_RESET_PASSWORD, registerReqDTO.getVerifyCode());
        if (!verify.getIsSuccess()) {
            throw new RuntimeException("验证码错误");
        }
        serveProviderService.updatePassword(registerReqDTO.getPhone(), registerReqDTO.getPassword());
    }


    @GetMapping("/currentUserInfo")
    @ApiOperation("获取当前用户信息")
    public ServeProviderInfoResDTO currentUserInfo() {
        return serveProviderService.currentUserInfo();
    }
}
